package com.jzcn.admin.controller.enterprise;

import com.jzcn.admin.annotation.ServerLog;
import com.jzcn.admin.base.BaseController;
import com.jzcn.common.dto.common.KeyWordDTO;
import com.jzcn.common.dto.enterprise.EnterpriseUserDTO;
import com.jzcn.common.dto.enterprise.OrgRecordDTO;
import com.jzcn.common.dto.enterprise.SearchEnterpriseUserDTO;
import com.jzcn.common.response.ResponseResult;
import com.jzcn.common.utils.JzPage;
import com.jzcn.service.EntEmployeeService;
import com.jzcn.service.EntOrgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/enterprise/org")
@Api(value = "OrgController", tags = "部门管理")
public class OrgController extends BaseController {

    @Resource
    EntOrgService entOrgService;

    @ApiOperation("部门查询")
    @GetMapping("/page")
    @RequiresPermissions("enterprise:org:page")
    @ServerLog(value ="部门查询", code= "employee:org:page")
    public ResponseResult<JzPage<OrgRecordDTO>> page(KeyWordDTO dto) {
        return ResponseResult.success(entOrgService.listPage(dto));
    }

    @ApiOperation("部门列表")
    @GetMapping("/list")
    public ResponseResult<List<OrgRecordDTO>> list() {
        return ResponseResult.success(entOrgService.orgList());
    }

    @ApiOperation("新增部门")
    @PostMapping("/create")
    @RequiresPermissions("enterprise:org:create")
    @ServerLog(value ="新增部门", code= "enterprise:org:create")
    public ResponseResult<Boolean> create(@RequestBody OrgRecordDTO dto) {
        return ResponseResult.success(entOrgService.create(dto));
    }


    @ApiOperation("编辑部门")
    @PutMapping("/update/{id}")
    @RequiresPermissions("enterprise:org:update")
    @ServerLog(value ="编辑部门", code= "enterprise:org:update")
    public ResponseResult<Boolean> update(@PathVariable("id") Integer id, @RequestBody OrgRecordDTO dto) {
        dto.setId(id);
        return ResponseResult.success(entOrgService.update(dto));
    }

    @ApiOperation("删除部门")
    @DeleteMapping("/delete/{id}")
    @RequiresPermissions("enterprise:org:delete")
    @ServerLog(value ="删除部门", code= "enterprise:org:delete")
    public ResponseResult<Boolean> delete(@PathVariable("id") Integer id) {
        return ResponseResult.success(entOrgService.delete(id));
    }

}
